import dayjs from "dayjs";


function formatTime(time) {
    return dayjs(time).format("YYYY年MM月DD日HH时mm分");
};

function getTime() {
    const h = new Date().getHours();
    if (h < 3) {
        return '现在是深夜啦，早点休息了哈'
    } else if (h < 6) {
        return '现在是凌晨了噢，注意休息哈'
    } else if (h < 11) {
        return '上午好'
    } else if (h < 13) {
        return '中午好'
    } else if (h < 19) {
        return '下午好'
    } else { return '晚上好' }
}

function throttle(cb, time) {
    let last = 0;
    return function () {
        const args = arguments,
            now = Date.now();
        if (now - last >= time) {
            cb.apply(this, args);
            last = now;
        } else {
            return;
        }
    }
}

export {
    formatTime,
    getTime,
    throttle
}
